<template>
  <el-container>
    <el-main>
      <div class="teacher">
        <div class="app-table">
          <div class="app-body">
            <div class="app-search">
              <el-form :inline="true" class="demo-form-inline" v-model="form">
                <el-form-item label="资产名称">
                  <el-input placeholder="请输入资产名称" v-model="form.name" @keyup.enter="searchEnter"></el-input>
                </el-form-item>

                <el-form-item>
                  <el-button class="serach_btn" type="primary" plain @click="onSubmit">搜索</el-button>
                </el-form-item>
              </el-form>
            </div>
            <el-table :data="list" size="default" style="width: 100%;" :row-class-name="tableRowClassName">
              <el-table-column prop="id" label="序号" width="100" />
              <el-table-column prop="name" label="资产名称" width="180" />
              <el-table-column prop="code" label="资产编号" width="180" />
              <el-table-column prop="model" label="型号" />
              <el-table-column prop="price" label="单价" width="130" />
              <el-table-column prop="deleteTeacherName" label="删除人" />
              <el-table-column prop="deleteTime" label="删除时间" width="200" />

              <template v-slot:empty>
                <el-empty description="暂无数据"></el-empty>
              </template>
            </el-table>
            <el-config-provider :locale="locale">
              <el-pagination :total="total" :page-size="limit" :page-sizes="[5, 10, 20, 30, 40, 50, 100]"
                layout="total, sizes, prev, pager, next, jumper" @size-change="changePageSize"
                @current-change="changeCurrentPage">
              </el-pagination>
            </el-config-provider>
          </div>
          <bottomView />
        </div>
      </div>
    </el-main>
  </el-container>
</template>

<script>
import bottomView from "@/components/bottom.vue";
import { ElConfigProvider, ElMessageBox, ElMessage } from "element-plus";
import zhCn from "element-plus/lib/locale/lang/zh-cn";
import { httpService } from "@/utils/httpService";
import { formatTime1 } from "@/utils/dateFormat";
import { Picture as IconPicture } from "@element-plus/icons-vue";
import { API_BASE_NAME2, API_BASE_NAME3 } from '../../constants';

export default {
  name: "BaseTeacherList",

  data() {
    return {
      type: 0,
      title: "",
      page: 0,
      pageSize: 10,
      total: 0,
      limit: 10,
      list: [],
      flagId: '',
      schoolNames: [],
      form: {
        name: "",
      },
      selectData: {},
      mobileNumber: '',
      campusName: API_BASE_NAME2,
      campusName1: API_BASE_NAME3,
    };
  },
  components: {
    IconPicture,
    ElConfigProvider,
    ElMessageBox,
    ElMessage,
    bottomView,
  },

  setup() {
    return {
      locale: zhCn,
    }
  },
  mounted() {
    this.getRecycleList();
    this.encrypt()
  },
  methods: {
    searchEnter: function (e) {
      // 使用 which 和 keyCode 属性来解决兼容问题
      var keyCode = window.event ? e.keyCode : e.which;
      var val = e.target.value;
      if (keyCode == 13 && val) {
        this.getRecycleList();
      }
    },
    encrypt() {
      let params = new FormData()
      params.append('dataToEncrypt', 19567930191)
      httpService("/javaApi/crypto/encrypt", params, "post").then(
        (data) => {
          console.log(data)
          // return data
        }
      );

    },

    onSubmit() {
      this.getRecycleList();
    },
    // 每页记录数改变，size：回调参数，表示当前选中的“每页条数”
    changePageSize(size) {
      this.pageSize = size;
      this.limit = size;
      this.getRecycleList();
    },

    // 改变页码，page：回调参数，表示当前选中的“页码”
    changeCurrentPage(page) {
      this.page = page;
      this.getRecycleList();
    },
    getRecycleList() {
      httpService(
        "/javaApi/faSubListRecycle/list/" + this.page + "/" + this.pageSize,
        {
          name: this.form.name,
        },
        "get"
      ).then((data) => {
        if (data.list) {
          this.list = data.list.map(item => {
            if (item.deleteTime) {
              return item.deleteTime = formatTime1(item.deleteTime)
            }
          })
        }
        // console.log(this.list);
        this.list = data.list;
        this.total = data.total;
      });
    },
  },
};
</script>

<style scoped>
.el-main {
  padding: 0px;
  text-align: left
}

.teacher-content {
  width: 100%;
}

.app-table {
  background: #eff3f5;
  padding: 10px;
}

.app-separator {
  padding-top: 10px;
  padding-bottom: 20px;
  padding-left: 10px;
}

.app-body {
  background: white;
  padding: 20px 20px 10px 20px;
  margin-bottom: 10px;
  min-height: calc(100vh - 244px);
}

.el-table .warning-row {
  --el-table-tr-bg-color: var(--el-color-warning-lighter);
}

.el-table .success-row {
  --el-table-tr-bg-color: var(--el-color-success-lighter);
}

.el-pagination {
  text-align: center;
  margin-top: 10px;
}

.serach_btn {
  background-color: #007EFF;
  color: #fff;
  border-radius: 8px;
  border: none;
}

.add_btn {
  background-color: #00c78c;
  color: #fff;
  border-radius: 8px;
  border: none;
}

.edit_btn {
  background-color: #fff;
  color: #00c78c;
  border: none;
}

.del_btn {
  background-color: #fff;
  color: #FF0000;
  border: none;
}

.face_btn {
  background-color: #fff;
  color: #ff8400;
  border: none;
}

.retire_btn {
  background-color: #fff;
  color: #007EFF;
  border: none;
}
</style>
